# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def reorderList(self, head: ListNode) -> None:
        """
        Do not return anything, modify head in-place instead.
        """
        if not head or not head.next or not head.next.next:
            return head
        total=0
        temp=head
        while temp:
            total+=1
            temp=temp.next
        count=0
        temp=head
        while count<total//2:
            temp=temp.next
            count+=1
        nextnode=temp.next
        temp.next=None
        temp=nextnode
        if temp.next:
            tail=temp.next
            temp.next=None
            while tail.next:
                nextnode=tail.next
                tail.next=temp
                temp=tail
                tail=nextnode
            tail.next=temp
        else:
            tail=temp
            temp.next=None
        while tail:
            temp2=tail.next
            temp=head.next
            head.next=tail
            tail.next=temp
            head=temp
            tail=temp2